using System;
using Glue;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_adding_a_relation
    {
        public class GuiPerson
        {
            public int Id { get; set; }
            public String FirstName { get; set; }
            public String LastName { get; set; }
            public String thisIsAField;
            public String ThisIsAnotherMethod() { return ""; }
        }

        public class DomainPerson
        {
            public int Id { get; set; }
            public String GivenName { get; set; }
            public String ThisIsAMethod() { return ""; }
        }

        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public When_adding_a_relation()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
        }

        [Fact]
        public void Should_accept_relation_away_from_a_method_with_no_parameters_and_return_value()
        {
            mapping.RelateTowardsRight(master => master.ThisIsAMethod(), t => t.LastName);
        }

        [Fact]
        public void Should_throw_exception_when_mapping_towards_a_method()
        {
            Assert.Throws<GlueException>(() =>
                mapping.RelateTowardsRight(master => master.GivenName, t => t.ThisIsAnotherMethod())
            );
        }

        [Fact]
        public void Should_throw_exception_when_relating_bidirectional_a_method()
        {
            Assert.Throws<GlueException>(() =>
                mapping.Relate(master => master.ThisIsAMethod(), t => t.LastName)
            );
        }

        [Fact]
        public void Should_accept_when_mapping_is_a_field()
        {
            //Assert.Throws<ArgumentException>(() =>
            mapping.Relate(master => master.GivenName, t => t.thisIsAField);
              //  );
        }

        [Fact]
        public void Should_not_throw_exception_when_mapping_is_a_property()
        {
            mapping.Relate(master => master.GivenName, t => t.FirstName);
        }

        [Fact]
        public void Should_handle_primitive_types()
        {
            mapping.Relate(master => master.Id, t => t.Id);
        }
    }
}